﻿using System;
using System.Windows.Forms;
using JsonObj;
using Newtonsoft.Json;
using System.IO;
using Newtonsoft.Json.Linq;

namespace JsonObj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string jsonArrayText1 = "[{'a':'a1','b':'b1'},{'a':'a2','b':'b2'}]";
            JArray ja = (JArray)JsonConvert.DeserializeObject(jsonArrayText1);
            string ja1a = ja[1]["a"].ToString();
            //或者
            JObject o = (JObject)ja[1];
            string oa = o["a"].ToString();
            textBox1.Text = oa;

            StringWriter sw = new StringWriter();
            JsonWriter writer = new JsonTextWriter(sw);

            writer.WriteStartObject();
            writer.WritePropertyName("input");
            writer.WriteValue("value");
            writer.WritePropertyName("output");
            writer.WriteValue("result");
            writer.WriteEndObject();
            writer.Flush();

            string jsonText = sw.GetStringBuilder().ToString();
            textBox1.Text = jsonText;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //右键解决方案，添加引用，将DLL文件添加进来
        }
    }
}
